package com.bdqn.config;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;


/**
 * GlobalExceptionHandler
 *
 * @author LILIBO
 * @since 2024-01-12
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView unauthorizedExceptionHandler(HttpServletRequest request, UnauthorizedException e) { // 出现异常之后会跳转到此方法
        ModelAndView mv = new ModelAndView("403"); // 设置跳转路径
        mv.addObject("exception", e); // 将异常对象传递过去
        mv.addObject("url", request.getRequestURL()); // 获得请求的路径
        return mv;
    }

}
